package org.skydiveapplibrary.ui;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import org.skydiveapplibrary.R;
import org.skydiveapplibrary.data.MoreCategory;

public class MoreCategoryAdapter extends BaseListAdapter<MoreCategory>
{
	public MoreCategoryAdapter(Context context)
	{
		super(context, MoreCategory.getItems());
	}
	
	@Override
	public View getView(int index, View view, ViewGroup parent)
	{
		view = super.getView(index, view, parent);
		
		// get rig
		MoreCategory category = getItems().get(index);
		// set icon
		Drawable icon = getIcon(category);
		((TextView)view).setCompoundDrawablePadding(TableStyler.dp2px(getContext(), 10));
		((TextView)view).setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
		
		return view;
	}

	@Override
	protected String getText(MoreCategory item)
	{
		return getContext().getString(item.getResourceId());
	}
	
	private Drawable getIcon(MoreCategory category)
	{
		Drawable icon = null;
		
		if (category == MoreCategory.Aircraft)
		{
			icon = getContext().getResources().getDrawable(R.drawable.icon_paper_plane);
		}
		else if (category == MoreCategory.SkydiveTypes)
		{
			icon = getContext().getResources().getDrawable(R.drawable.icon_jump_type);
		}
		else if (category == MoreCategory.Locations)
		{
			icon = getContext().getResources().getDrawable(R.drawable.icon_location);
		}
		else if (category == MoreCategory.WingLoadCalculator)
		{
			icon = getContext().getResources().getDrawable(R.drawable.icon_calculator);
		}
		else if (category == MoreCategory.ImportExport)
		{
			icon = getContext().getResources().getDrawable(R.drawable.icon_import_export);
		}
		else if (category == MoreCategory.Settings)
		{
			icon = getContext().getResources().getDrawable(R.drawable.icon_settings);
		}
		
		return icon;
	}
}
